草庐IT

SQL FOREIGN KEY 约束

全部标签

c# - 为什么在运行时出现通用约束冲突?

Thisquestionisunlikelytohelpanyfuturevisitors;itisonlyrelevanttoasmallgeographicarea,aspecificmomentintime,oranextraordinarilynarrowsituationthatisnotgenerallyapplicabletotheworldwideaudienceoftheinternet.Forhelpmakingthisquestionmorebroadlyapplicable,visitthehelpcenter。9年前关闭。在尝试创建严重依赖泛型的类的新实例时遇

c# - Entity Framework 中的唯一约束

这个问题在这里已经有了答案:UniquekeysinEntityFramework4(5个答案)关闭9年前。如何将实体(EntityFramework)中的某些属性设置为唯一?一种可能是将其设为主键,但这不是我想要的。

c# - 多重性与参照约束冲突

我收到以下EF错误:Agent_MailingAddress::MultiplicityconflictswiththereferentialconstraintinRole'Agent_MailingAddress_Target'inrelationship'Agent_MailingAddress'.BecauseallofthepropertiesintheDependentRolearenon-nullable,multiplicityofthePrincipalRolemustbe1它似乎在它执行时抛出这个base.OnModelCreating(modelBuilder).

c# - 为什么不能继承/分层强制执行泛型类型约束

元素类别publicclassItem{publicboolCheck(intvalue){...}}具有泛型类型约束的基础抽象类publicabstractclassClassBasewhereTItem:Item{protectedIListitems;publicClassBase(IEnumerableitems){this.items=items.ToList();}publicabstractboolCheckAll(intvalue);}没有约束的继承类publicclassMyClass:ClassBase{publicoverrideboolCheckAll(intv

c# - 受约束泛型类型参数的继承

我知道不可能从泛型类型参数继承,但在实现抽象类型派生的通用代理时会很方便:-)有谁知道为什么这是不可能的?示例C#:abstractclassFoo{publicvirtualvoidBar(){//nop}}classFooProxy:TFoowhereTFoo:Foo{publicoverridevoidBar(){//dosomestuffbeforebase.Bar();//dosomestuffafter}}编辑:一些更多的代码来说明如何使用它的示例。考虑以下Foo的派生词:classFooX:Foo{publicstringX{get;set;}publicoverride

c# - 是否有可用于 + 运算符的通用约束?

是否可以添加一些“where”类型约束来编译以下代码?publicclassPlus:BinaryOperatorwhereT:...{publicoverrideTEvaluate(IContextcontext){returnleft.Evaluate(context)+right.Evaluate(context);}}谢谢:) 最佳答案 C#中没有这样的设备。不过,有几个选项可用:在C#4.0和.NET4.0(或更高版本)中,使用dynamic,它支持+但不提供编译时检查在.NET3.5(或更高版本)中,MiscUtil提供

c# - 在 SQLite 中启用外键约束

我在C#中使用SQLite,并且有一些表定义了外键。现在,我知道默认情况下外键约束在SQLite中不强制执行,但我想将它们打开。是否可以通过代码来实现?我查了一个相关的question,但我不确定如何通过C#代码来完成。我正在使用可用于VisualStudio2008的最新SQLite插件来设计我的表格。conn.Open();SQLiteCommandcmd=newSQLiteCommand("PRAGMAforeign_keys=ON",conn);cmd.ExecuteNonQuery();conn.Close();我需要此更改在重新打开此连接时持续存在。可能吗?

c# - 如何在 C# 中对泛型类型指定多个约束?

对多种类型施加约束的语法是什么?基本示例:classAnimalwhereSpeciesType:Species我想在以下定义中对这两种类型进行约束,这样SpeciesType必须继承自Species并且OrderType必须继承自顺序:classAnimal 最佳答案 publicclassAnimalwhereSpeciesType:SpecieswhereOrderType:Order{} 关于c#-如何在C#中对泛型类型指定多个约束?,我们在StackOverflow上找到一个类

C# 7.3 枚举约束 : Why can't I use the nullable enum?

既然我们有了枚举约束,为什么编译器不允许我编写这段代码?publicstaticTResult?ToEnum(thisStringvalue,TResult?defaultValue)whereTResult:Enum{returnString.IsNullOrEmpty(value)?defaultValue:(TResult?)Enum.Parse(typeof(TResult),value);}编译器说:ErrorCS0453Thetype'TResult'mustbeanon-nullablevaluetypeinordertouseitasparameter'T'intheg

c# - 为什么泛型类型约束会导致无隐式引用转换错误?

我已经创建了几个接口(interface)和通用类来处理议程约会:interfaceIAppointmentwhereT:IAppointmentProperties{TProperties{get;set;}}interfaceIAppointmentEntrywhereT:IAppointment{DateTimeDate{get;set;}TAppointment{get;set;}}interfaceIAppointmentProperties{stringDescription{get;set;}}classAppointment:IAppointmentwhereT:IAp